package com.gyf.szcrm.service;
import com.gyf.szcrm.mapper.CourseOrderMapper;
import com.gyf.szcrm.model.CourseOrder;
import com.gyf.szcrm.model.MonthIncome;
import com.gyf.szcrm.model.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CourseOrderServiceImpl implements CourseOrderService {

    @Autowired
    CourseOrderMapper courseOrderMapper;

    @Override
    public List<MonthIncome> getMonthIncomes() {
      return courseOrderMapper.getMonthIncomes();

    }

    @Override
    public void update(CourseOrder courseOrder) {
        courseOrderMapper.update(courseOrder);
    }

    @Override
    public void deleteByOrderId(String order_id) {
        courseOrderMapper.deleteByOrderId(order_id);
    }

    @Override
    public CourseOrder findByOrderId(String order_id) {
        return courseOrderMapper.findByOrderId(order_id);
    }

    @Override
    public void save(CourseOrder courseOrder) {
        courseOrderMapper.insert(courseOrder);
    }

    @Override
    public PageResult<CourseOrder> findPageResult(CourseOrder condition, int page, int pageSize) {
        PageResult<CourseOrder> pageResult=new PageResult<>();
        pageResult.setCode(0);
        Map<String,Object> param= new HashMap<String,Object>();
        param.put("start",(page-1)*pageSize);
        param.put("pageSize",pageSize);
        param.put("condition",condition);
        int totalCount=courseOrderMapper.findCountByMap(param);
        pageResult.setCount(totalCount);
        List<CourseOrder> courseOrderList=courseOrderMapper.findListByMap(param);
        pageResult.setData(courseOrderList);
        return pageResult;
    }
}
